package com.jinzecloud.reportapproval.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jinzecloud.reportapproval.bean.SpeedOperationTable;
import com.jinzecloud.reportapproval.bean.VegetationRecordForm;
import com.jinzecloud.reportapproval.dto.AuditParam;
import com.jinzecloud.reportapproval.dto.DataStagingParam;
import com.jinzecloud.reportapproval.enums.StateEnum;
import com.jinzecloud.reportapproval.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import com.jinzecloud.reportapproval.bean.TemperatureHumidity;
import com.jinzecloud.reportapproval.service.TemperatureHumidityService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;



/**
 * 
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-12-04 20:49:45
 */
@RestController
@RequestMapping("reportapproval/temperaturehumidity")
public class TemperatureHumidityController {
    @Autowired
    private TemperatureHumidityService temperatureHumidityService;

    @Autowired
    private AdminService adminService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("reportapproval:temperaturehumidity:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = temperatureHumidityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("reportapproval:temperaturehumidity:info")
    public R info(@PathVariable("id") Integer id){
		TemperatureHumidity temperatureHumidity = temperatureHumidityService.getById(id);

        return R.ok().put("temperatureHumidity", temperatureHumidity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("reportapproval:temperaturehumidity:save")
    public R save(@RequestBody TemperatureHumidity temperatureHumidity){
        List<TemperatureHumidity> projectCode = temperatureHumidityService.list(new QueryWrapper<TemperatureHumidity>().eq("project_code", temperatureHumidity.getProjectCode()));
        if (projectCode.size() > 0) return R.error("编号："+temperatureHumidity.getProjectCode()+"已存在，请勿重复添加！");
        temperatureHumidity.setStatus(StateEnum.UN_SUBMIT.getState()).setWordPath("").setPdfPath("");
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        temperatureHumidity.setUserId(adminService.getIdByName(authentication.getName()));
		temperatureHumidityService.save(temperatureHumidity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("reportapproval:temperaturehumidity:update")
    public R update(@RequestBody TemperatureHumidity temperatureHumidity){
		temperatureHumidityService.updateById(temperatureHumidity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("reportapproval:temperaturehumidity:delete")
    public R delete(@RequestBody Integer[] ids){
		temperatureHumidityService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/viewPdf/{id}")
    public String viewPdf(@PathVariable("id") Integer id){
        return temperatureHumidityService.viewPdf(id);
    }

    @PostMapping("/auditList")
    public R auditList(@RequestBody DataStagingParam param) {
        return R.ok().setData(temperatureHumidityService.auditList(param));
    }

    @PostMapping("/review")
    public R review(@RequestBody TemperatureHumidity temperatureHumidity) {
        temperatureHumidityService.updateById(new TemperatureHumidity().setId(temperatureHumidity.getId()).setStatus(0));
        return R.ok();
    }

    @PostMapping("/audit")
    public R audit(@RequestBody AuditParam auditParam) {
        return temperatureHumidityService.audit(auditParam);
    }

}
